package second.thread.threadlocaltest;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.alibaba.ttl.TtlRunnable;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: heweiwei
 * @time: 2025/3/16 19:49
 * @description:
 */
public class TTLTest {


    public static void main(String[] args) {
        TransmittableThreadLocal<String> context=new TransmittableThreadLocal<>();
        context.set("main set hello before");

        ExecutorService executorService = Executors.newFixedThreadPool(1);

        Runnable task = () -> {
            System.out.println(" 子线程值: " + context.get());
        };

        TtlRunnable ttlRunnable = TtlRunnable.get(task);
        executorService.submit(ttlRunnable);

        context.set("main set hello after");

        executorService.submit(ttlRunnable);
    }
}
